home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.03 Mar 90 / Debug CDEF Code / debug_test_cdef_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-31  |  3.5 KB  |  150 lines  |  [TEXT/KAHL]

  1. /******** System includes ********/
  2. #include <Quickdraw.h>
  3. #include <ControlMgr.h>
  4. #include <MemoryMgr.h>
  5. #include <OSUtil.h>
  6. #include <WindowMgr.h>
  7. #include <EventMgr.h>
  8. /**********************************/
  9.  
  10. /******** typedefs ********/
  11. typedef struct {
  12.     char *cdef_ptr ;
  13. } CJMP, *CJMP_PTR, **CJMP_HDL ;
  14. /**********************************/
  15.  
  16. /******** defines ********/
  17. #define NULL    0L
  18. /**********************************/
  19.  
  20. /******** prototypes ********/
  21. extern pascal long _main( ) ;
  22. void main( void ) ;
  23. void TestControl( void ) ;
  24. /**********************************/
  25.  
  26. /******** globals ********/
  27. CJMP_HDL cjmp_hdl ;
  28. Rect test_window_rect = { 40, 10, 300, 400 } ;
  29. Rect test_control_rect = { 10, 10, 34, 150 } ;
  30. /**********************************/
  31.  
  32. void main( )
  33. {
  34.     /* Initialize the macintosh managers */
  35.     InitGraf( ( Ptr) &thePort ) ;
  36.     InitFonts( ) ;
  37.     InitWindows( ) ;
  38.     InitCursor( ) ;
  39.     InitMenus( ) ;
  40.     TEInit( ) ;
  41.     InitDialogs( 0L ) ;
  42.     MoreMasters( ) ;
  43.     MoreMasters( ) ;
  44.     MoreMasters( ) ;
  45.     MoreMasters( ) ;
  46.     MoreMasters( ) ;
  47.     MoreMasters( ) ;
  48.     MoreMasters( ) ;
  49.     MoreMasters( ) ;
  50.     MoreMasters( ) ;
  51.     MoreMasters( ) ;
  52.     MoreMasters( ) ;
  53.     FlushEvents( everyEvent, 0 ) ;
  54.  
  55.     if( ( cjmp_hdl = (CJMP_HDL)GetResource( 'CJMP', 9999 ) )  == 0L ) {
  56.         /* First create CJMP structure */
  57.         cjmp_hdl = (CJMP_HDL)NewHandle( sizeof( CJMP ) ) ;
  58.     
  59.         /* Now make it into a resource so that the dummy cdef can access it */
  60.         AddResource( cjmp_hdl, 'CJMP', 9999, "\pcdef jump structure" ) ;
  61.     }
  62.     (**cjmp_hdl).cdef_ptr = (char *)_main ;
  63.     
  64.     /* Now call test control routine */
  65.     TestControl( ) ;
  66.     
  67.     /* Now remove the resource */
  68.     RmveResource( cjmp_hdl ) ;
  69.     
  70.     return ;
  71. }
  72. void TestControl( )
  73. {
  74.     WindowPtr window_ptr ;
  75.     ControlHandle control_hdl ;
  76.     ControlHandle control_hdl2 ;
  77.     long tmp ;
  78.     EventRecord event ;
  79.     Point pt ;
  80.     int part_code ;
  81.     int last_part_code ;
  82.     ControlHandle which_control ;
  83.     
  84.     /* Open the window */
  85.     window_ptr = NewWindow( NULL, &test_window_rect, "\ptest window", TRUE, 1, 
  86.                             (WindowPtr)-1L, FALSE, 0L ) ;
  87.                             
  88.     if( window_ptr == NULL ) return ;
  89.     
  90.     SetPort( window_ptr ) ;
  91.                             
  92.     /* Open the control */
  93.     control_hdl = NewControl( window_ptr, &test_control_rect, "\ptest control",
  94.                               TRUE, 0, 0, 0, 32, 0L ) ;
  95.     OffsetRect( &test_control_rect, 150, 50 ) ;
  96.     control_hdl2 = NewControl( window_ptr, &test_control_rect, "\ptest control",
  97.                               TRUE, 0, 0, 0, 32, 0L ) ;
  98.     
  99.     /* Now start miniature event loop */
  100.     while( TRUE ) {
  101.     
  102.         GetNextEvent( everyEvent, &event ) ;
  103.         
  104.         pt = event.where ;
  105.         
  106.         SetPort( window_ptr ) ;
  107.         
  108.         GlobalToLocal( &pt ) ;
  109.         
  110.         if( event.what == mouseDown ) {
  111.         
  112.             part_code = FindControl( pt, window_ptr, &which_control ) ;
  113.             
  114.             if( which_control == NULL ) {
  115.                 if( (**control_hdl).contrlHilite != 0 ) {
  116.                     HiliteControl( control_hdl, 0 ) ;
  117.                 }
  118.                 if( (**control_hdl2).contrlHilite != 0 ) {
  119.                     HiliteControl( control_hdl2, 0 ) ;
  120.                 }
  121.                 SysBeep( 5 ) ;
  122.             }else{
  123.                 part_code = TrackControl( which_control, pt, (ProcPtr)-1L ) ;
  124.                 HiliteControl( which_control, part_code ) ;
  125.                 if( which_control == control_hdl ) {
  126.                     if( (**control_hdl2).contrlHilite != 0 ) {
  127.                         HiliteControl( control_hdl2, 0 ) ;
  128.                     }
  129.                 }
  130.                 if( which_control == control_hdl2 ) {
  131.                     if( (**control_hdl).contrlHilite != 0 ) {
  132.                         HiliteControl( control_hdl, 0 ) ;
  133.                     }
  134.                 }
  135.             }
  136.         }
  137.         if( event.what == keyDown ) {
  138.             break ;
  139.         }
  140.     }
  141.           
  142.     /* Close the control */
  143.     DisposeControl( control_hdl ) ;
  144.     DisposeControl( control_hdl2 ) ;
  145.  
  146.     /* Close the window */
  147.     DisposeWindow( window_ptr ) ;
  148.     return ;
  149. }
  150.